package myJs.myPkg.reactRouterDom

import japgolly.scalajs.react.CtorType.ChildArg
import japgolly.scalajs.react.facade.React
import japgolly.scalajs.react.{Children, JsFnComponent}
import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

/** Created by yz on 20/9/2023
  */
object Route {

  @JSImport("react-router-dom", "Route")
  @js.native
  object RawComponent extends js.Object

  case class Props(key: js.UndefOr[String] = js.undefined, path: String, element: React.Element)

  val Component = JsFnComponent[ObjectOrWritten[Props], Children.Varargs](RawComponent)

  def apply(key: js.UndefOr[String] = js.undefined, path: String, element: React.Element)(children: ChildArg*) =
    Component(Props(key, path, element))(children: _*)

}
